<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('自然灾害视频列表')" />
</head>
<body class="gray-bg">

<video hidden id="videoElement" width="640" height="360" preload="metadata">
    <source id="videoElementSource" src="" type="video/mp4">
</video>
<canvas id="canvasElement" style="display:none;"></canvas>
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="ziran:zrVideo:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
               <!-- <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="ziran:zrVideo:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="ziran:zrVideo:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="ziran:zrVideo:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('ziran:zrVideo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('ziran:zrVideo:remove')}]];
        var prefix = ctx + "ziran/zrVideo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "自然灾害视频",
                columns: [
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'typeName',
                    title: '类型'
                },
                {
                    field: 'videoUrl',
                    title: '自然灾害视频',
                    formatter: function (value, row, index) {
                        $("#videoElementSource").attr('src', value);

                        var canvas = document.getElementById('canvasElement');
                        var ctx;
                        if (canvas.getContext) {
                            ctx = canvas.getContext('2d');
                            // 使用 ctx 进行绘图
                        }
                        var video = document.getElementById('videoElement'); // 获取DOM元素
                        var img = $('#thumbnail'); // 获取img元素

                        // 监听视频的元数据加载事件
                        video.addEventListener('loadedmetadata', function() {
                            // 设置canvas的尺寸与视频一致
                            canvas.width = video.videoWidth;
                            canvas.height = video.videoHeight;
                            // 绘制视频的第一帧到canvas上
                            ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
                            // 将canvas内容转换为DataURL，并设置为img的src属性
                            img.attr('src', canvas.toDataURL('image/png')); // 使用jQuery设置src属性
                        });

                        var html=`<video id="videoElement2" style="width: 250px!important;height: 150px!important;" controls>
                                <source src="`+value+`" type="video/mp4">
                                您的浏览器不支持 HTML5 video 标签。
                            </video>
                            <canvas id="canvasElement2" style="display:none;"></canvas>`;
                        return html;
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>